/*
cAndy Apple Core: An Apple //e emulator engine
    - based almost entirely on AppleWin

Copyright (C) 1994-1996, Michael O'Brien
Copyright (C) 1999-2001, Oliver Schmidt
Copyright (C) 2002-2005, Tom Charlesworth
Copyright (C) 2006-2008, Tom Charlesworth, Michael Pohoreski, Nick Westgate
Copyright (C) 2009-2010, Garnet Ulrich

cAndy Apple Core is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

cAndy Apple Core is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with cAndy Apple Core; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "StdAfx.h"
#pragma  hdrstop

static BYTE  keycode         = 0;	// Current Apple keycode
static DWORD keyboardqueries = 0;
static BOOL  keywaiting      = 0;


//
// ----- ALL GLOBALLY ACCESSIBLE FUNCTIONS ARE BELOW THIS LINE -----
//

//===========================================================================

void KeybReset()
{
	keywaiting = 0;
}

//===========================================================================
void KeybSetKeycode(int CAKey) //gu - new function for jni routine to inject the keycode
{
    keycode = CAKey;
    keywaiting = 1;
}


//===========================================================================
BYTE KeybGetKeycode ()		// Used by MemCheckPaging() & VideoCheckMode()
{
	return keycode;
}

//===========================================================================

BYTE  KeybReadData (WORD, WORD, BYTE, BYTE, ULONG)
{
	keyboardqueries++;

	return keycode | (keywaiting ? 0x80 : 0);

}

//===========================================================================

BYTE  KeybReadFlag (WORD, WORD, BYTE, BYTE, ULONG)
{
	keyboardqueries++;

	keywaiting = 0;
	return keycode;

}

DWORD KeybGetSnapshot(SS_IO_Keyboard* pSS)
{
    pSS->keyboardqueries    = keyboardqueries;
    pSS->keywaiting = keywaiting;
    pSS->keycode = keycode;
    return 0;
}

DWORD KeybSetSnapshot(SS_IO_Keyboard* pSS)
{
    keyboardqueries = pSS->keyboardqueries;
    keywaiting = pSS->keywaiting;
    keycode = pSS->keycode;
    return 0;
}

